package com.delay.queue.delayedqueue.jdkdelayqueue;

import com.delay.queue.model.MessageTask;

import java.util.concurrent.DelayQueue;

/**
 * @author gxing
 * @desc
 * @date 2021/3/9
 */
public class MainTest {

    public static void main(String[] args) throws InterruptedException {
        MessageTask msg1 = new MessageTask("A", System.currentTimeMillis() + 30000L);
        MessageTask msg2 = new MessageTask("B", System.currentTimeMillis() + 20000L);
        MessageTask msg3 = new MessageTask("C", System.currentTimeMillis() + 50000L);

        DelayQueue<MessageTask> delayQueue = new DelayQueue<>();
        delayQueue.add(msg1);
        delayQueue.add(msg2);
        delayQueue.add(msg3);

        int size = delayQueue.size();

        System.out.println("start------------------------------------------------" + System.currentTimeMillis());
        for (int i = 0; i < size; i++) {
            System.out.println(delayQueue.take() + "------------" + System.currentTimeMillis());
        }
        System.out.println();
    }
}
